﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class findSequenceOfGivenSum
{
    static void Main()
    {
        int[] arr = {4, 3, 1, 4, 2, 5, 8};
        Console.Write("Enter sum S = ");
        int s = Convert.ToInt32(Console.ReadLine());
        int Start = 0;
        int len = 0;
        for (int element = 0; element < arr.Length; element++) 
        {
            int sum = arr[element];
            for (int count = (element + 1); count < arr.Length; count++) 
            {
                sum += arr[count];
                if (sum == s) 
                {
                    Start = element;
                    len = count;
                    break;
                }
            }
            if (sum == s) 
            {
                break;
            }
        }
        for (int i = Start; i < len+1; i++) 
        {
            Console.WriteLine("[{0}], {1}", i, arr[i]);
        }
    }
}

